package core_prepare

import (
	"github.com/kataras/iris/v12"
	"gopkg.in/mgo.v2/bson"
	"iris_test/config"
	models "iris_test/models/supsite"
	"strings"
	"tyz/tools"
	"tyz/tools/encode"
)

func initRoute(ctx iris.Context) {
	routeRes := new(models.UsersiteRoute).Init().FindOne(bson.M{
		"siteid" : bson.ObjectIdHex(config.Conf["siteid"].(string)),
		"hash" : encode.Md5(ctx.Request().URL.Path),
		"type" : 1,
		"state" :1,
	})
	var mvcArr []string
	if len(*routeRes) != 0 {
		mvcArr = strings.Split((*routeRes)["mca"].(string), "/")
		mvcArr = tools.RemoveStrArrEmpty(mvcArr)
	}
	if len(mvcArr) == 3 {
		config.Conf["module"] = mvcArr[0]
		config.Conf["controller"] = mvcArr[1]
		config.Conf["action"] = mvcArr[2]
	}
}